package com.DataWrapper;

import com.Core.GameEngine;
import com.Object.ObjType;
import com.Object.SeaObject;

public class MapModel
{	private SeaObject[][] objMap;

	public MapModel()
	{	objMap = new SeaObject[GameEngine.MAP_SIZE][GameEngine.MAP_SIZE];
	}
	private ObjType TypeOf(String s)
	{	int i = Integer.parseInt(s);
		switch (i)
		{	case GameEngine.ROCK		:	return ObjType.Rock;
			case GameEngine.TORNADO		:	return ObjType.Tornado;
			case GameEngine.GHOST_SHIP	:	return ObjType.GhostShip;
			case GameEngine.PEARL		:	return ObjType.Pearl;
			case GameEngine.SHELL		:	return ObjType.Shell;
			case GameEngine.CORAIL		:	return ObjType.Corail;
			case GameEngine.SMALL_FISH	:	return ObjType.SmallFish;
			case GameEngine.MEDIUM_FISH	:	return ObjType.MediumFish;
			case GameEngine.BIG_FISH	:	return ObjType.BigFish;
			case GameEngine.GIANT_FISH	:	return ObjType.GiantFish;
			case GameEngine.MERMAID		:	return ObjType.Mermaid;
			case GameEngine.SHIP		:	return ObjType.Ship;
			case GameEngine.SHIP_WRECK	:	return ObjType.Shipwreck;
			case GameEngine.TREASURE	:	return ObjType.Treasure;
			case GameEngine.TREASURE_MAP:	return ObjType.TreasureMap;
			case GameEngine.POSEIDON	:	return ObjType.Poseidon;
			default						:	return ObjType.Null;
		}
	}
	public MapModel(String[] data)
	{	objMap = new SeaObject[GameEngine.MAP_SIZE][GameEngine.MAP_SIZE];
		for (int i=0;i<GameEngine.MAP_SIZE;i++)
		{	int base = GameEngine.MAP_SIZE*(GameEngine.MAP_SIZE-1)+i;
			for (int j=0;j<GameEngine.MAP_SIZE;j++)
				objMap[i][j] = SeaObject.CreateObject(TypeOf(data[base-GameEngine.MAP_SIZE*j]));
		}
	}
	public void Set(int row, int col, ObjType type)
	{	objMap[row][col] = SeaObject.CreateObject(type);
	}
	public void Swap(int r1, int c1, int r2, int c2)
	{	SeaObject tmp=objMap[r1][c1];
		objMap[r1][c1]=objMap[r2][c2];
		objMap[r2][c2]=tmp;
	}
	public SeaObject Get(int row, int col)
	{	return objMap[row][col];
	}
}
